package common;

/**
 * A basic pair object
 * 
 * @author Gal Lalouche
 * @param <First> The first type
 * @param <Second> The second type
 */
public class Pair<First, Second> {
	/**
	 * The first object in the pair
	 */
	public final First	first;
	/**
	 * The second object in the pair
	 */
	public final Second	second;

	/**
	 * Creates a new pair
	 * 
	 * @param first The first object
	 * @param second The second object
	 */
	public Pair(First first, Second second) {
		super();
		this.first = first;
		this.second = second;
	}

	/**
	 * Creates a new pair from the types. <br>
	 * syntactic sugar of the constructor
	 * 
	 * @param <First> The type of the first object
	 * @param <Second> The type of the second object
	 * @param first The first object
	 * @param second The second object
	 * @return A new pair made of the arguments
	 */
	public static <First, Second> Pair<First, Second> of(First first, Second second) {
		return new Pair<>(first, second);
	}

	@Override
	public String toString() {
		return "[" + first + "," + second + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (prime * result) + ((first == null) ? 0 : first.hashCode());
		result = (prime * result) + ((second == null) ? 0 : second.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Pair<?, ?> other = (Pair<?, ?>)obj;
		if (first == null) {
			if (other.first != null) {
				return false;
			}
		} else if (!first.equals(other.first)) {
			return false;
		}
		if (second == null) {
			if (other.second != null) {
				return false;
			}
		} else if (!second.equals(other.second)) {
			return false;
		}
		return true;
	}

}
